var t = require("../../../@babel/runtime/helpers/defineProperty"), a = require("../DHttp").default;

Page({
    data: {
        hiddenInputPassPopup: !0,
        memberId: null,
        memberInfo: null,
        stock: "0.00",
        giftValue: 0,
        payPassword: {
            has: !1,
            turnedOn: !1,
            inputValue: ""
        }
    },
    onLoad: function(e) {
        var n = this;
        a.request("plugin.credit-inventory.frontend.controllers.give.center").then(function(a) {
            var e, s = a.stock, i = a.has_password, o = a.need_password;
            n.setData((t(e = {
                stock: s
            }, "payPassword.turnedOn", o), t(e, "payPassword.has", i), e)), n.checkPayPassword();
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    displayInputPassPopup: function() {
        !1 !== this.checkPayPassword() && (!1 !== this.data.payPassword.turnedOn ? this.data.memberId && this.data.memberInfo ? this.data.giftValue <= 0 ? wx.showToast({
            title: "赠送的信用值不能小于0",
            icon: "none"
        }) : this.setData({
            hiddenInputPassPopup: !this.data.hiddenInputPassPopup
        }) : wx.showToast({
            title: "需要先指定会员才能赠送",
            icon: "none"
        }) : this.confirmGiveGift());
    },
    inputMemberId: function(t) {
        var a = t.detail.value;
        this.setData({
            memberId: a,
            memberInfo: null
        });
    },
    inputGiftValue: function(t) {
        var a = t.detail.value;
        this.setData({
            giftValue: a
        });
    },
    inputPayPassword: function(a) {
        var e = a.detail.value;
        this.setData(t({}, "payPassword.inputValue", e));
    },
    getMemberInfo: function() {
        var t = this;
        this.data.memberId ? (wx.showLoading({
            title: "查询中",
            mask: !0
        }), a.request("plugin.credit-inventory.frontend.controllers.give.detail", {
            member_id: this.data.memberId
        }).then(function(a) {
            wx.hideLoading(), t.setData({
                memberInfo: a
            });
        }).catch(function(a) {
            var e = a.msg;
            wx.hideLoading(), t.setData({
                memberInfo: null
            }), wx.showToast({
                title: e,
                icon: "none"
            });
        })) : wx.showToast({
            title: "请输入会员ID",
            icon: "none"
        });
    },
    confirmGiveGift: function() {
        var e = this;
        if (!1 !== this.checkPayPassword()) if (this.data.memberId && this.data.memberInfo) if (this.data.giftValue <= 0) wx.showToast({
            title: "赠送的信用值不能小于0",
            icon: "none"
        }); else {
            wx.showLoading({
                title: "请稍等",
                mask: !0
            });
            var n = {
                recipient_id: this.data.memberId,
                give_amounts: this.data.giftValue
            };
            if (this.data.payPassword.turnedOn) {
                if (!this.data.payPassword.inputValue || this.data.payPassword.inputValue.length < 3) return void wx.showToast({
                    title: "请输入正确的提现密码",
                    icon: "none"
                });
                n.password = this.data.payPassword.inputValue;
            }
            a.post("plugin.credit-inventory.frontend.controllers.give.handle", n).then(function(a) {
                wx.hideLoading(), wx.showToast({
                    title: "赠送成功",
                    icon: "none"
                }), e.setData(t({
                    hiddenInputPassPopup: !0
                }, "payPassword.inputValue", ""));
            }).catch(function(t) {
                var a = t.msg;
                wx.hideLoading(), wx.showToast({
                    title: a,
                    icon: "none"
                });
            });
        } else wx.showToast({
            title: "需要先指定会员才能赠送",
            icon: "none"
        });
    },
    checkPayPassword: function() {
        return !this.data.payPassword.turnedOn || !1 !== this.data.payPassword.has || (wx.showModal({
            title: "未设置提现密码",
            content: "您还未设置提现密码，设置提现密码后才可以赠送",
            showCancel: !0,
            cancelText: "取消",
            confirmText: "确定",
            success: function(t) {
                t.confirm && wx.navigateTo({
                    url: "/packageA/member/set_balance_password/set_balance_password"
                });
            }
        }), !1);
    }
});